<template>
  <el-card class="vocabulary-card" :class="{ expanded: isExpanded, compact: compact }" shadow="hover">
    <div class="vocab-header" @click="toggleExpand">
      <div class="vocab-word">
        <span class="word">{{ vocabulary.word }}</span>
        <span v-if="!compact" class="phonetic">/{{ vocabulary.phonetic }}/</span>
      </div>
      <div class="expand-icon" v-if="!compact">
        {{ isExpanded ? '−' : '+' }}
      </div>
    </div>
    
    <div class="vocab-details" v-show="isExpanded || compact">
      <div class="definition" v-if="vocabulary.definition || vocabulary.translation">
        <span v-if="vocabulary.definition">{{ vocabulary.definition }}</span>
        <span v-if="vocabulary.definition && vocabulary.translation"> - </span>
        <span v-if="vocabulary.translation">{{ vocabulary.translation }}</span>
      </div>
      
      <div class="examples" v-if="(isExpanded || !compact) && vocabulary.examples && vocabulary.examples.length">
        <ul>
          <li v-for="(example, index) in vocabulary.examples" :key="index">
            {{ example }}
          </li>
        </ul>
      </div>
      
      <div class="audio" v-if="(isExpanded || !compact) && vocabulary.audio">
        <el-button @click="playAudio" type="primary" size="small" round>
          🔊 Pronounce
        </el-button>
      </div>
    </div>
  </el-card>
</template>

<script>
import { ElCard, ElButton } from 'element-plus'

export default {
  name: 'VocabularyCard',
  components: {
    ElCard,
    ElButton
  },
  props: {
    vocabulary: {
      type: Object,
      required: true,
      default: () => ({
        word: '',
        phonetic: '',
        definition: '',
        translation: '',
        examples: [],
        audio: ''
      })
    },
    compact: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      isExpanded: false
    }
  },
  methods: {
    toggleExpand() {
      if (!this.compact) {
        this.isExpanded = !this.isExpanded
      }
    },
    
    playAudio() {
      // In a real implementation, this would play the pronunciation audio
      console.log(`Playing audio for: ${this.vocabulary.word}`)
      this.$emit('play-audio', this.vocabulary.word)
    }
  }
}
</script>

<style scoped>
.vocabulary-card {
  margin-bottom: 10px;
  transition: box-shadow 0.3s ease;
}

.vocabulary-card.compact {
  margin-bottom: 0;
}

.vocab-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 15px;
  background-color: #f8f9fa;
  cursor: pointer;
  margin: -20px;
}

.vocabulary-card.compact .vocab-header {
  padding: 5px 10px;
  background-color: #e9f7ef;
}

.vocab-word {
  display: flex;
  flex-direction: column;
}

.vocabulary-card.compact .vocab-word {
  flex-direction: row;
  align-items: baseline;
  gap: 8px;
}

.word {
  font-size: 1em;
  font-weight: bold;
  color: #333;
}

.phonetic {
  color: #666;
  font-style: italic;
  margin-top: 3px;
  font-size: 0.9em;
}

.expand-icon {
  font-size: 1.2em;
  font-weight: bold;
  color: #42b983;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.vocab-details {
  padding: 10px 15px;
  border-top: 1px solid #eee;
  margin: 0 -20px -20px -20px;
}

.vocabulary-card.compact .vocab-details {
  padding: 5px 10px;
  border-top: none;
  background-color: #f8f9fa;
}

.definition {
  margin-bottom: 8px;
  font-size: 0.95em;
}

.examples ul {
  margin: 0;
  padding-left: 20px;
}

.examples li {
  margin-bottom: 5px;
  font-size: 0.9em;
}
</style>